﻿package Views
{	
	import Player.SnakeHead;
	import flash.display.Sprite;
	import flash.geom.Point;

	public class Field extends Sprite
	{
		
		public static const BORDER_COLOR:uint = 0xFFFF33;
		private var _fieldWidth:Number;
		private var _fieldHeight:Number;
		private var _collisionMap:CollisionField;
		private var snakes:Array = new Array();
		
		public function Field(newWidth:Number, newHeight:Number)
		{
			_fieldWidth = newWidth;
			_fieldHeight = newHeight;
			_collisionMap = new CollisionField(_fieldWidth,_fieldHeight);
			this.cacheAsBitmap = true;
			this.mouseEnabled = false;
			addChild(collisionMap);
		}
		
		public function updateSnake(snake:SnakeHead, oldPosition:Point){
			collisionMap.updateSnake(snake,oldPosition);
		}
		
		/**
		 * Function to add snake displays to field
		 */
		public function addSnake(snake:SnakeView):void{
			snakes.push(snake);
			addChild(snake);
		}
		
		public function emptyField():void{
			collisionMap.emptyField();
		}
		
		public function get fieldWidth():Number{
			return _fieldWidth;
		}
		public function get fieldHeight():Number{
			return _fieldHeight;
		}
		
		public function get collisionMap():CollisionField{
			return _collisionMap;
		}
	}
}